package com.tianpengtech.common.validator.rules.numberic;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.common.validator.AbstractRule;

public class MustBeNumberic extends AbstractRule {

	private String rex ="^\\d+$";
	public MustBeNumberic(String value,String msg){
		this.value = value;
		this.msg = msg;
	}
	@Override
	public boolean validate() throws ValidateException {
		String v = StringUtils.trim((String) this.value);
		Pattern pattern = Pattern.compile(this.rex);
        Matcher matcher = pattern.matcher(v);
        if (!matcher.matches()) {
            throw new ValidateException(this.msg);
        }
		return false;
	}
}
